home *** CD-ROM | disk | FTP | other *** search
/ Transformers: Revenge of …he Game: Press Kit (USA) / Transformers - Revenge of the Fallen - The Game - Press Kit (USA).bin / Transformers.swf / scripts / fl / video / SeekBarAccImpl.as < prev    next >
Text File  |  2009-06-19  |  11KB  |  351 lines

  1. package fl.video
  2. {
  3.    import flash.accessibility.Accessibility;
  4.    import flash.accessibility.AccessibilityImplementation;
  5.    import flash.accessibility.AccessibilityProperties;
  6.    import flash.display.DisplayObject;
  7.    import flash.display.Sprite;
  8.    import flash.events.Event;
  9.    import flash.events.FocusEvent;
  10.    import flash.events.TimerEvent;
  11.    import flash.utils.Dictionary;
  12.    import flash.utils.Timer;
  13.    
  14.    use namespace flvplayback_internal;
  15.    
  16.    public class SeekBarAccImpl extends AccessibilityImplementation
  17.    {
  18.       
  19.       private static const ROLE_SYSTEM_INDICATOR:uint = 39;
  20.       
  21.       private static const ROLE_SLIDER:uint = 51;
  22.       
  23.       private static const STATE_SYSTEM_FOCUSABLE:uint = 1048576;
  24.       
  25.       private static const EVENT_OBJECT_SELECTION:uint = 32774;
  26.       
  27.       private static const ROLE_SYSTEM_PUSHBUTTON:uint = 43;
  28.       
  29.       private static const STATE_SYSTEM_FOCUSED:uint = 4;
  30.       
  31.       private static const STATE_SYSTEM_SELECTABLE:uint = 2097152;
  32.       
  33.       private static const EVENT_OBJECT_FOCUS:uint = 32773;
  34.       
  35.       private static const STATE_SYSTEM_SELECTED:uint = 2;
  36.       
  37.       private static const EVENT_OBJECT_VALUECHANGE:uint = 32782;
  38.       
  39.       private static const EVENT_OBJECT_LOCATIONCHANGE:uint = 32779;
  40.       
  41.       private static const STATE_SYSTEM_NORMAL:uint = 0;
  42.       
  43.       private static const STATE_SYSTEM_UNAVAILABLE:uint = 1;
  44.        
  45.       
  46.       private var _timer:Timer;
  47.       
  48.       private var _vc:FLVPlayback;
  49.       
  50.       protected var master:Sprite;
  51.       
  52.       protected var role:uint;
  53.       
  54.       private var _cachedPercentage:Number;
  55.       
  56.       public function SeekBarAccImpl(param1:Sprite)
  57.       {
  58.          var n:int = 0;
  59.          var i:int = 0;
  60.          var sprite:Sprite = param1;
  61.          super();
  62.          stub = false;
  63.          master = sprite;
  64.          if(!master.accessibilityProperties)
  65.          {
  66.             master.accessibilityProperties = new AccessibilityProperties();
  67.          }
  68.          master.accessibilityProperties.forceSimple = true;
  69.          var events:Array = eventsToHandle;
  70.          if(events)
  71.          {
  72.             n = events.length;
  73.             i = 0;
  74.             while(i < n)
  75.             {
  76.                master.addEventListener(events[i],eventHandler);
  77.                i++;
  78.             }
  79.          }
  80.          master.addEventListener(FocusEvent.FOCUS_IN,focusInHandler);
  81.          try
  82.          {
  83.             _vc = Object(master).uiMgr._vc;
  84.             _vc.addEventListener(VideoEvent.PLAYHEAD_UPDATE,eventHandler);
  85.          }
  86.          catch(e:Error)
  87.          {
  88.          }
  89.          role = SeekBarAccImpl.ROLE_SLIDER;
  90.       }
  91.       
  92.       public static function createAccessibilityImplementation(param1:Sprite) : void
  93.       {
  94.          param1.accessibilityImplementation = new SeekBarAccImpl(param1);
  95.       }
  96.       
  97.       public static function enableAccessibility() : void
  98.       {
  99.       }
  100.       
  101.       protected function getName(param1:uint) : String
  102.       {
  103.          var _loc2_:String = "";
  104.          switch(param1)
  105.          {
  106.             case 1:
  107.                _loc2_ = "Page Left";
  108.                break;
  109.             case 2:
  110.                _loc2_ = "Position";
  111.                break;
  112.             case 3:
  113.                _loc2_ = "Page Right";
  114.                break;
  115.             case 0:
  116.                _loc2_ = "";
  117.          }
  118.          return _loc2_;
  119.       }
  120.       
  121.       override public function get_accName(param1:uint) : String
  122.       {
  123.          var _loc2_:String = "";
  124.          if(param1 == 0 && master.accessibilityProperties && master.accessibilityProperties.name && master.accessibilityProperties.name != "")
  125.          {
  126.             _loc2_ += master.accessibilityProperties.name + " ";
  127.          }
  128.          _loc2_ += getName(param1) + getStatusName();
  129.          return _loc2_ != null && _loc2_ != "" ? _loc2_ : null;
  130.       }
  131.       
  132.       private function secondsToTime(param1:Number) : String
  133.       {
  134.          var _loc2_:String = null;
  135.          var _loc3_:String = null;
  136.          var _loc4_:String = null;
  137.          var _loc5_:int = 0;
  138.          var _loc6_:int = 0;
  139.          var _loc7_:Number = NaN;
  140.          _loc5_ = param1 >= 3600 ? int(param1 / 3600) : 0;
  141.          _loc6_ = param1 >= 60 ? int(param1 / 60 - _loc5_ * 60) : 0;
  142.          _loc7_ = param1 - (_loc5_ * 3600 + _loc6_ * 60);
  143.          _loc2_ = String(_loc5_);
  144.          _loc3_ = String(_loc6_).length == 1 && _loc5_ > 0 ? "0" + String(_loc6_) : String(_loc6_);
  145.          _loc4_ = String(Math.floor(_loc7_)).length == 1 ? "0" + String(_loc7_) : String(_loc7_);
  146.          var _loc8_:String = _loc3_ + ":" + _loc4_;
  147.          if(_loc5_ > 0)
  148.          {
  149.             _loc8_ = _loc2_ + ":" + _loc3_ + ":" + _loc4_;
  150.          }
  151.          return _loc8_;
  152.       }
  153.       
  154.       override public function accDoDefaultAction(param1:uint) : void
  155.       {
  156.          var nearestCuePoint:Object = null;
  157.          var nextCuePoint:Object = null;
  158.          var childID:uint = param1;
  159.          var percent:Number = _vc.playheadPercentage;
  160.          nearestCuePoint = _vc.findNearestCuePoint(_vc.playheadTime);
  161.          if(childID == 1)
  162.          {
  163.             percent -= _vc.seekBarScrubTolerance * 2;
  164.             _vc.playheadPercentage = Math.max(percent,0);
  165.          }
  166.          else if(childID == 3)
  167.          {
  168.             if(_vc.playheadPercentage >= 99)
  169.             {
  170.                return;
  171.             }
  172.             if(nearestCuePoint != null && nearestCuePoint.index < (nearestCuePoint.array as Array).length - 1)
  173.             {
  174.                try
  175.                {
  176.                   nextCuePoint = _vc.findCuePoint(nearestCuePoint.array[nearestCuePoint.index + 1]);
  177.                   if(nextCuePoint && _vc.isFLVCuePointEnabled(nextCuePoint))
  178.                   {
  179.                      if(isNaN(Number(_vc.metadata.videocodecid)))
  180.                      {
  181.                         _vc.playheadPercentage = Math.max(nextCuePoint.time / _vc.totalTime * 100,Math.min(99,_vc.playheadPercentage + _vc.seekBarScrubTolerance * 2));
  182.                      }
  183.                      else
  184.                      {
  185.                         _vc.playheadTime = nextCuePoint.time;
  186.                      }
  187.                   }
  188.                }
  189.                catch(err:Error)
  190.                {
  191.                }
  192.             }
  193.          }
  194.       }
  195.       
  196.       protected function eventHandler(param1:Event) : void
  197.       {
  198.          var _loc2_:SeekBarAccImpl = null;
  199.          if(Accessibility.active)
  200.          {
  201.             switch(param1.type)
  202.             {
  203.                case VideoEvent.PLAYHEAD_UPDATE:
  204.                   _cachedPercentage = _vc.playheadPercentage;
  205.                   _loc2_ = this;
  206.                   if(Accessibility.active)
  207.                   {
  208.                      Accessibility.sendEvent(master,0,EVENT_OBJECT_SELECTION);
  209.                      Accessibility.sendEvent(master,0,EVENT_OBJECT_VALUECHANGE,true);
  210.                   }
  211.                   if(!_timer)
  212.                   {
  213.                      _timer = new Timer(10);
  214.                      _timer.removeEventListener(TimerEvent.TIMER,sendAccessibilityEvent);
  215.                      _timer.addEventListener(TimerEvent.TIMER,sendAccessibilityEvent);
  216.                      _timer.start();
  217.                   }
  218.             }
  219.          }
  220.       }
  221.       
  222.       private function sendAccessibilityEvent(param1:TimerEvent) : void
  223.       {
  224.          if(_cachedPercentage != _vc.playheadPercentage)
  225.          {
  226.             param1.target.stop();
  227.             param1.target.removeEventListener(TimerEvent.TIMER,sendAccessibilityEvent);
  228.             _timer = undefined;
  229.             if(Accessibility.active)
  230.             {
  231.                Accessibility.sendEvent(master,0,EVENT_OBJECT_SELECTION);
  232.                Accessibility.sendEvent(master,0,EVENT_OBJECT_VALUECHANGE,true);
  233.             }
  234.          }
  235.       }
  236.       
  237.       override public function accLocation(param1:uint) : *
  238.       {
  239.          var _loc2_:Object = master;
  240.          var _loc3_:UIManager = _vc.uiMgr as UIManager;
  241.          var _loc4_:DisplayObject = _loc3_.controls[UIManager.SEEK_BAR] as DisplayObject;
  242.          var _loc5_:Dictionary;
  243.          var _loc6_:ControlData = (_loc5_ = UIManager(_loc3_).ctrlDataDict as Dictionary)[_loc4_];
  244.          switch(param1)
  245.          {
  246.             case 0:
  247.                if(_loc6_.hit_mc)
  248.                {
  249.                   _loc2_ = _loc6_.hit_mc;
  250.                }
  251.                break;
  252.             case 1:
  253.             case 3:
  254.                if(_loc6_.progress_mc)
  255.                {
  256.                   _loc2_ = _loc6_.progress_mc;
  257.                }
  258.          }
  259.          return _loc2_;
  260.       }
  261.       
  262.       override public function get_accState(param1:uint) : uint
  263.       {
  264.          return uint(getState(param1));
  265.       }
  266.       
  267.       private function getStatusName() : String
  268.       {
  269.          return "";
  270.       }
  271.       
  272.       protected function getState(param1:uint) : uint
  273.       {
  274.          var _loc2_:uint = STATE_SYSTEM_NORMAL;
  275.          if(param1 == 0)
  276.          {
  277.             if(!master.mouseEnabled || !master.tabEnabled)
  278.             {
  279.                _loc2_ |= STATE_SYSTEM_UNAVAILABLE;
  280.             }
  281.             else
  282.             {
  283.                _loc2_ |= STATE_SYSTEM_FOCUSABLE;
  284.             }
  285.             if(Sprite(master).stage.focus == master)
  286.             {
  287.                _loc2_ |= STATE_SYSTEM_FOCUSED;
  288.             }
  289.          }
  290.          return _loc2_;
  291.       }
  292.       
  293.       override public function get_accDefaultAction(param1:uint) : String
  294.       {
  295.          if(param1 == 1 || param1 == 3)
  296.          {
  297.             return "Press";
  298.          }
  299.          return null;
  300.       }
  301.       
  302.       override public function getChildIDArray() : Array
  303.       {
  304.          var _loc1_:Array = [];
  305.          var _loc2_:uint = 0;
  306.          while(_loc2_ < 3)
  307.          {
  308.             _loc1_[_loc2_] = _loc2_ + 1;
  309.             _loc2_++;
  310.          }
  311.          return _loc1_;
  312.       }
  313.       
  314.       private function focusInHandler(param1:Event) : void
  315.       {
  316.          if(Accessibility.active)
  317.          {
  318.             Accessibility.sendEvent(master,0,EVENT_OBJECT_FOCUS);
  319.             Accessibility.sendEvent(master,0,EVENT_OBJECT_VALUECHANGE,true);
  320.          }
  321.       }
  322.       
  323.       override public function get_accRole(param1:uint) : uint
  324.       {
  325.          if(param1 == 0)
  326.          {
  327.             return role;
  328.          }
  329.          if(param1 == 2)
  330.          {
  331.             return ROLE_SYSTEM_INDICATOR;
  332.          }
  333.          return ROLE_SYSTEM_PUSHBUTTON;
  334.       }
  335.       
  336.       override public function get_accValue(param1:uint) : String
  337.       {
  338.          if(param1 == 0)
  339.          {
  340.             return Math.round(_vc.playheadPercentage).toString() + "%";
  341.          }
  342.          return null;
  343.       }
  344.       
  345.       protected function get eventsToHandle() : Array
  346.       {
  347.          return [];
  348.       }
  349.    }
  350. }
  351.